package com.gy.flink;

import org.apache.flink.streaming.api.functions.source.SourceFunction;

import java.util.concurrent.TimeUnit;

public class MyFlinkSource implements SourceFunction<Long> {
    private long number = 1L;
    private boolean isRunning = true;

    @Override
    public void run(SourceContext<Long> sc) throws Exception {
        while (isRunning) {
            sc.collect(number);
            number++;
            TimeUnit.SECONDS.sleep(3);
        }
    }

    /**
     * 任务停止的时候运行
     */
    @Override
    public void cancel() {
        isRunning = false;
    }
}
